package com.mva.Vendor_DAO;

import com.mva.common.DataDictionaryConstants;
import com.mva.common.Displayable;
import com.mva.common.Validator;

/*******************************************************************************
 The <big><b>Vendor</b></big> class implements the <b>Displayable</b> &
 <b>Cloneable</b> interfaces to create an <b>Vendor</b> object
 <br><br>
 @author D.Merkling - 1:33:38 PM - Aug 22, 2011
 <br><br>
 @version 1.2  
*******************************************************************************/
public class Vendor implements Displayable, Cloneable, DataDictionaryConstants
  {
   private String Vndr;
   private String Typ;
   private String Nm;
   private int    Addr;
   private String Phn;
   private String Phn2;
   private String Eml;
   private String Eml2;
	   

   /*******************************************************************************
	This constructor creates a new <b>Vendor</b> object with default values
   *******************************************************************************/
   public Vendor ()
	 {
	  this.Vndr = " ";
	  this.Typ  = " ";
	  this.Nm   = " ";
	  this.Addr = 0;
	  this.Phn  = " ";
	  this.Phn2 = " ";
	  this.Eml  = " ";
	  this.Eml2 = " ";
	 }

   /*******************************************************************************
	This constructor creates a new <b>Vendor</b> object with attribute values as
	defined by the provided parameters
	<br><br>
	@param Vendor ID A <b><i>String</i></b> variable
	@param Vendor type A <b><i>String</i></b> variable
	@param Vendor name A <b><i>String</i></b> variable
	@param Addr code An <b><i>int</i></b> variable
	@param Phone #1 A <b><i>String</i></b> variable
	@param Phone #2 A <b><i>String</i></b> variable
	@param Email #1 A <b><i>String</i></b> variable
	@param Email #2 A <b><i>String</i></b> variable
   *******************************************************************************/
   public Vendor (String Vndr, String Typ, String Nm, int Addr, String Phn, String Phn2, String Eml, String Eml2)
	 {
	  this.Vndr = Vndr;
	  this.Typ  = Typ;
	  this.Nm   = Nm;
	  this.Addr = Addr;
	  this.Phn  = Phn;
	  this.Phn2 = Phn2;
	  this.Eml  = Eml;
	  this.Eml2 = Eml2;
	 }
   
   /*******************************************************************************
	Clones the current <b>Vendor</b> object to create a new one
	<br><br>
	@return Vendor - A <b>Vendor</b> object
	@throws CloneNotSupportedException 
   *******************************************************************************/
   public Object clone () throws CloneNotSupportedException
	 {
	  return super.clone();
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>Vndr</b> attribute for the current
	<b>Vendor</b> object
	<br><br>
	The value must be uppercase, trimmed, & left-justified
	<br><br>
	@param Addr A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setVndr (String vndr)
	 {
	  String tmpVndr = vndr.trim();
	         tmpVndr = tmpVndr.toUpperCase();
	  this.Vndr      = tmpVndr;
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>Vndr</b> attribute from the current
	<b>Vendor</b> object
	@return Vndr - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getVndr ()
	 {
	  return Vndr;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>Typ</b> code attribute for the current
	<b>Vendor</b> object
	<br><br>
	The value must be uppercase, trimmed, left-justified, & exist in the cd_val
	table in the MVA/VT segment
	<br><br>
	@param Vendor type code A <b><i>String</i></b> variable
	@return Success/failure - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setTyp (String typ)
	 {
      String tmpTyp   = typ.trim();
	         tmpTyp   = tmpTyp.toUpperCase();
	  boolean isValid = Validator.isCodeValid("MVA", "VT", tmpTyp);
      if (isValid)
	    {
	     this.Typ     = tmpTyp;
	     return true;
	    }
	  else
	    {
	     return false;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>Typ</b> code attribute from the current
	<b>Vendor</b> object
	@return Vendor type code - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getTyp ()
	 {
	  return Typ;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>Nm</b> attribute for the current
	<b>Vendor</b> object
	<br><br>
	The value must be trimmed & left-justified
	<br><br>
	@param Vendor name A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setNm (String nm)
	 {
	  String tmpNm = nm.trim();
	  this.Nm      = tmpNm;
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>Nm</b> attribute from the current
	<b>Vendor</b> object
	@return Vendor name - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getNm ()
	 {
	  return Nm;
	 }

   /*******************************************************************************
	Sets the <b><i>int</i></b> <b>Addr</b> attribute for the current
	<b>Vendor</b> object
	<br><br>
	The value must be an unsigned, positive integer
	table
	<br><br>
	@param Addr An <b><i>int</i></b> variable
	@return Success/failure - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setAddr (int addr)
	 {
	  boolean isValid = Validator.isAddressValid(addr);
	  if (isValid)
	    {
		 this.Addr = addr;
		 return true;  
	    }
	  else
	    {
		 this.Addr = 0;
		 return false; 
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>int</i></b> <b>Addr</b> attribute from the current
	<b>Vendor</b> object
	@return Addr - An <b><i>int</i></b> variable
   *******************************************************************************/
   public int getAddr ()
	 {
	  return Addr;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>phone #1</b> attribute for the current
	<b>Vendor</b> object
	<br><br>
	The value must be trimmed, left-justified, & formatted as a proper phone
	number - 999-999-9999
	<br><br>
	@param Phone #1 A <b><i>String</i></b> variable
	@return isValid - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setPhn (String inPhn)
	 {
	  String phn1 = inPhn.trim();
	  String phn2 = "";
             phn2 = Validator.validatePhone(phn1);
	  if (phn2.equals("**BAD**"))
	    {
		 System.out.println("Phone #1 not valid; saved as blanks");
		 return false;
	    }
	  else
	    {
		 this.Phn = phn2;
		 return true;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>phone #1</b> attribute from the current
	<b>Vendor</b> object
	<br><br>
	@return Phone #1 - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getPhn ()
	 {
	  return Phn;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>phone #2</b> attribute for the current
	<b>Vendor</b> object
	<br><br>
	The value must be trimmed, left-justified, & formatted as a proper phone
	number - 999-999-9999
	<br><br>
	@param Phone #2 A <b><i>String</i></b> variable
	@return isValid - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setPhn2 (String inPhn)
	 {
	  String phn1 = inPhn.trim();
	  String phn2 = "";
             phn2 = Validator.validatePhone(phn1);
	  if (phn2.equals("**BAD**"))
	    {
		 System.out.println("Phone #2 not valid; saved as blanks");
		 return false;
	    }
	  else
	    {
		 this.Phn2 = phn2;
		 return true;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>phone #2</b> attribute from the current
	<b>Vendor</b> object
	<br><br>
	@return Phone #2 - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getPhn2 ()
	 {
	  return Phn2;
	 }
   
   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>email #1</b> attribute for the current
	<b>Vendor</b> object
	<br><br>
	The value must be trimmed, left-justified, & formatted as a proper email
	address - xxxxxxxx@yyyyyyyy.zzz
	<br><br>
	@param Email #1 A <b><i>String</i></b> variable
	@return isValid - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setEmail (String inEml)
	 {
	  String  eml1    = inEml.trim();
	  boolean isValid = false;
	          isValid = Validator.validateEmail(eml1);
	  if (isValid)
	    {
		 this.Eml = eml1;
		 return true;
	    }
	  else
	    {
		 System.out.println("Email #1 not valid format; saved as blanks");
		 return false;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>email #1</b> attribute from the current
	<b>Vendor</b> object
	<br><br>
	@return Email #1 - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getEmail ()
	 {
	  return Eml;
	 }
   
   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>email #2</b> attribute for the current
	<b>Vendor</b> object
	<br><br>
	The value must be trimmed, left-justified, & formatted as a proper email
	address - xxxxxxxx@yyyyyyyy.zzz
	<br><br>
	@param Email #2 A <b><i>String</i></b> variable
	@return isValid - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setEmail2 (String inEml)
	 {
	  String  eml2    = inEml.trim();
	  boolean isValid = false;
	          isValid = Validator.validateEmail(eml2);
	  if (isValid)
	    {
		 this.Eml2= eml2;
		 return true;
	    }
	  else
	    {
		 System.out.println("Email #2 not valid format; saved as blanks");
		 return false;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>email #2</b> attribute from the current
	<b>Vendor</b> object
	<br><br>
	@return Email #2 - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getEmail2 ()
	 {
	  return Eml2;
	 }
   
   /*******************************************************************************
	Determines whether or not all of the attribute values of one <b>Vendor</b>
	object are equal to all of the attribute values of a second <b>Vendor</b>
	object
	<br><br>
	@param object A	<b>Vendor</b> object
	@return true/false - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean equals(Object object)
     {
      if (object instanceof Vendor)
        {
         Vendor vndr2 = (Vendor) object;
         if (Vndr.equals(vndr2.getVndr())   &&
             Typ.equals(vndr2.getTyp())     &&
             Nm.equals(vndr2.getNm())       &&
             Addr == vndr2.getAddr()        &&
             Phn.equals(vndr2.getPhn())     &&
             Phn2.equals(vndr2.getPhn2())   &&
             Eml.equals(vndr2.getEmail())   &&
             Eml2.equals(vndr2.getEmail2()))
         return true;
        }
      return false;
     }
   
   /*******************************************************************************
	Retrieves a formatted list of the attribute values of the current
	<b>Vendor</b> object
	<br><br>
	@return string - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String toString()
	 {
	  return "Vendor ID: " + this.Vndr        + "\n" +
	         "Type     : " + this.Typ         + "\n" +
		     "Name     : " + this.Nm          + "\n" +
	         "Address  : " + this.Addr        + "\n" +
		     "Phone #1 : " + this.getPhn()    + "\n" +
		     "Phone #2 : " + this.getPhn2()   + "\n" +
	         "Email #1 : " + this.getEmail()  + "\n" +
             "Email #2 : " + this.getEmail2() + "\n";
	 }
   
   /*******************************************************************************
	Retrieves a formatted displayable list of the attribute values of the current
	<b>Vendor</b> object
	<br><br>
	@return string - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getDisplayText()
    {
	  return toString();
    }
  }
